package dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import dao.UserDAO;
import entity.User;

public class HibernateUserDAO extends HibernateDaoSupport implements UserDAO{

	@Override
	public User findByEmail(String email) throws Exception {
		String hql = "from User where email=?";
		List<User> list = getHibernateTemplate().find(hql,email);
		if (list.size()<=0) {
			return null;
		}else {
			return list.get(0);
		}
	}

	@Override
	public boolean findByEmailName(String email) throws Exception {
		return false;
	}

	@Override
	public User findByEmailVerifyCode(String code) throws Exception {
		String hql = "from User where emailVerifyCode =?";
		List<User> list = getHibernateTemplate().find(hql,code);
		System.out.println(list);
		if (list.size()<=0) {
			return null;
		}else {
			return list.get(0);
		}
	}

	@Override
	public User findById(Integer id) {
		return (User) getHibernateTemplate().get(User.class, id);
	}

	@Override
	public void modify(User user) throws Exception {
		getHibernateTemplate().update(user);
	}

	@Override
	public void save(User user) throws Exception {
		getHibernateTemplate().save(user);
	}

	@Override
	public void UpdateEmailVerifyCode(String code) throws Exception {
	}
	
}
